<script setup lang="ts">
import YkPagination from '@yk/components/pagination/YkPagination.vue'
import { Pages } from '@typings/pages'
import YkTableColumn from '@yk/components/table-column/YkTableColumn.vue'
import { ObjectUtil } from '@utils/object-util'
import { ElForm } from 'element-plus'
import { TableUtil } from '@utils/table-util'
import { MountedCheck } from '@/utils'
import { getSimCardAlarmListByPageAPI } from '@/api/sim-card'
import { CardDTO } from '@/api/entity/sim-card'

const router = useRouter()
defineOptions({ name: 'SimManage' })

const mc = new MountedCheck()
onMounted(() => {
  searchHandle()
  mc.end()
})

onActivated(() => {
  if (mc.isMounted()) return
  getTableData()
})

// region TODO 查询
const searchParams = reactive({
  // SIM卡号
  cardno: ''
})
function searchHandle () {
  pages.pageNum = 1
  exportParams.value = ObjectUtil.copy(searchParams)
  getTableData()
}
// endregion

// region TODO 表格数据
const pages = reactive(new Pages())
const tableData = shallowRef<CardDTO[]>([])
function getTableData () {
  const loading = ElLoading.service()
  getSimCardAlarmListByPageAPI({
    ...pages.getParams(),
    param: searchParams
  }).then((res) => {
    res.result().then((rdata) => {
      tableData.value = rdata.records
      pages.total = rdata.total
    })
  })
  loading.close()
}
function delTableItem (id: string) {
  ElMessageBox.confirm('删除当前设备？', '删除提醒').then(() => {
    // delDeviceAPI({ id }).then((res) => {
    //   res.result().then(() => {
    //     getTableData()
    //   })
    // })
  })
}
// endregion

// region TODO 导出
const exportParams = shallowRef<typeof searchParams>()
// endregion

</script>

<template>
  <div class="layout_view d-flex" style="min-height: 100%">
    <div class="c_card-page w-100 flex-1">
      <div class="c_card_header c_card-title bor-divider-b">告警记录</div>
      <!--搜索表单-->
      <el-form inline class="c_form-search mt-3" @submit.prevent="searchHandle">
        <el-form-item label="条件：">
          <el-input v-model="searchParams.cardno" placeholder="请输入SIM卡号" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="searchHandle">查询</el-button>
        </el-form-item>
      </el-form>
      <!--表格-->
      <el-table class="c_table-page w-100" stripe :data="tableData">
        <el-table-column label="#" type="index" :index="TableUtil.indexMethod.bind(this, pages)" />
        <yk-table-column label="卡号" prop="cardno" />
        <yk-table-column label="报警内容" prop="alarmMessage" />
        <yk-table-column label="报警流量（KB）" prop="surplus" />
        <yk-table-column label="关联网关" prop="gateWayName" />
        <yk-table-column label="创建时间" prop="createdAt" />
      </el-table>
      <!--分页-->
      <el-affix target=".c_table-page" position="bottom" :offset="0">
        <yk-pagination class="c_table-pagination-page" :pages="pages" @handle="getTableData" />
      </el-affix>
    </div>
  </div>
</template>

<style scoped lang="scss">
</style>
